import { createStore, createLogger } from 'vuex'
import user from './modules/user'
import cart from './modules/cart'
import category from './modules/category'
import createPersistedstate from 'vuex-persistedstate'
// vuex-persistedstate包是基于和本地localStorage同步的插件库
// 它需要在vuex配置一个属性plugins
// import Cookies from 'js-cookie'

export default createStore({
  modules: {
    user,
    cart,
    category
  },

  plugins: [
    // createPersistedstate({
    //   key: 'xtx-133', // 存入本地name
    //   storage: {
    //     getItem: (key) => Cookies.get(key),
    //     setItem: (key, value) => Cookies.set(key, value),
    //     removeItem: (key) => Cookies.remove(key)
    //   }
    // }),
    createLogger(), // 用于打印vue3数据变化前-后
    createPersistedstate({
      key: 'xtx-133', // 存入本地name
      paths: ['user', 'cart'] // 需要监听的两个模块
    })
  ]
})
